import { kgjHttp as http } from '@/services/http';
import type { SortAndLimit, ListResult } from '@/types/api/common';

import type {
  SalesOrderListDto,
  SalesOrderListResult,
  SalesUserListDto,
  SalesUserListResult,
  ClueListDto,
  ClueListResult,
  ClueCountResult,
  AddClueResult,
  AllClueResult,
  MyClueUpdateDto
} from '@/types/api/crm-kgj/sales';

/** 销售管理相关 */

/** 获取销售订单列表 */
export const getSalesOrderList = (payload: { data: SalesOrderListDto; params: SortAndLimit }) => {
  return http<ListResult<SalesOrderListResult>>({
    method: 'post',
    url: '/api/salesorder/list',
    ...payload
  });
};
/** 获取销售用户列表 */
export const getSalesUserList = (payload: { data: SalesUserListDto; params: SortAndLimit }) => {
  return http<ListResult<SalesUserListResult>>({
    method: 'post',
    url: '/api/order/sales/user/list',
    ...payload
  });
};

/** 获取我的线索列表 */
export const getClueList = (payload: { data: ClueListDto; params: SortAndLimit }) => {
  return http<ListResult<ClueListResult>>({
    method: 'post',
    url: '/api/salesclue/list',
    ...payload
  });
};

/** 获取线索数量 */
export const getClueCount = () => {
  return http<ClueCountResult>({
    method: 'get',
    url: '/api/salesclue/date/count'
  });
};

/** 获取线索 */
export const addClue = () => {
  return http<ListResult<AddClueResult>>({
    method: 'post',
    url: '/api/salesclue/add/clue'
  });
};

/** 获取所有线索 */
export const getAllClue = (payload: { data: any; params: SortAndLimit }) => {
  return http<ListResult<AllClueResult>>({
    method: 'post',
    url: '/api/salesclue/all/list',
    ...payload
  });
};

/** 我的线索 - 送会员 */
export const giftVip = (data: { sales_user_id: number }) =>
  http({
    method: 'post',
    url: '/api/salesclue/give/clueuserlevel',
    data
  });

/** 我的线索 - 操作 - 获取线索跟进 */

/** 我的线索 - 操作 - 获取用户信息 */
export const getSalesUserInfo = (params: { sales_user_id: number }) =>
  http({
    method: 'get',
    url: '/api/salesclue/salesuser',
    params
  });

/** 我的线索 - 操作 - 获取跟进历史 */
export const getFollowLogs = (params: { sales_user_id: number }) =>
  http({
    method: 'get',
    url: '/api/salesclue/followlog/list',
    params
  });
/** 我的线索 - 操作 - 获取销售订单 */
export const getSalesOrderLogs = (params: { sales_user_id: number }) =>
  http({
    method: 'get',
    url: '/api/salesclue/salesorder/list',
    params
  });
/** 我的线索 - 操作 - 添加跟进日志 */
export const addClueFollow = (data: MyClueUpdateDto) =>
  http({
    method: 'post',
    url: '/api/salesclue/add/cluefollow',
    data
  });
